//
//  SISSLoginNetworkingManager+Registration.m
//  SISSAPP
//
//  Created by 优房网 on 2017/4/21.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSLoginNetworkingManager+Registration.h"

@implementation SISSLoginNetworkingManager (Registration)

// 3.1.1.1 模糊搜索小区 GET请求
- (void)fuzzySearchHouseResourceCommunityWithKeyword:(NSString *)keyword successBlock:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{@"name":keyword};
    
    [kLoginNetworkingManager GETWithURLString:URL_HOUSE_RESOURCE_PNAME_LIST parameters:parameters success:^(id responseObject) {
        
        NSLog(@"3.1.1.1 模糊搜索小区: responseObject-->%@",responseObject);
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
            return;
        }
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } faile:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 3.1.1.2 根据小区获取楼栋列表 GET请求
- (void)requestBuildingResourceWithCommunityName:(NSString *)communityName successBlock:(void (^)(NSArray<SISSBuildingNumberModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{@"name":communityName};
    
    [kLoginNetworkingManager GETWithURLString:URL_HOUSE_RESOURCE_DONG_BNUM_LIST parameters:parameters success:^(id responseObject) {
        
        NSLog(@"3.1.1.2 根据小区获取楼栋列表: responseObject-->%@",responseObject);
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
            return;
        }
        
        NSArray *dataArr = responseObject[@"data"];
        
        NSArray *buildingArr = [NSArray yy_modelArrayWithClass:[SISSBuildingNumberModel class] json:dataArr];
        if (successBlock) {
            successBlock(buildingArr);
        }
        
    } faile:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 3.1.1.3 根据楼栋获取房号列表 GET请求
- (void)requestHouseRoomNumberWithBuilding:(NSString *)buildingId successBlock:(void (^)(NSArray<SISSRoomNumberModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{@"dongId":buildingId};
    
    [kLoginNetworkingManager GETWithURLString:URL_HOUSE_RESOURCE_HOUSE_DNUM_LIST parameters:parameters success:^(id responseObject) {
        
        NSLog(@"3.1.1.3 根据楼栋获取房号列表: responseObject-->%@",responseObject);
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
            return;
        }
        NSArray *dataArr = responseObject[@"data"];
        
        NSArray *roomNumArr = [NSArray yy_modelArrayWithClass:[SISSRoomNumberModel class] json:dataArr];
        if (successBlock) {
            successBlock(roomNumArr);
        }
        
    } faile:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 3.1.1.4 根据房源获取推荐售价 GET请求
- (void)requestHouseEstateHomePageInfoWithCommunityName:(NSString *)communityName successBlock:(void (^)(SISSHouseEstateHomePageInfoModel *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{@"name":communityName};
    
    [kLoginNetworkingManager GETWithURLString:URL_HOUSE_ESTATE_HOME_INFO parameters:parameters success:^(id responseObject) {
        
        NSLog(@"3.1.1.4 根据房源获取推荐售价: responseObject-->%@",responseObject);
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
            return;
        }
        
        NSDictionary *dataDict = responseObject[@"data"];
        
        SISSHouseEstateHomePageInfoModel *model = [SISSHouseEstateHomePageInfoModel yy_modelWithDictionary:dataDict];
        if (successBlock) {
            successBlock(model);
        }
        
    } faile:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 3.1.1 房源登记
- (void)enrollHouseResourceWithHouseModel:(SISSHouseResourceModel *)houseModel successBlock:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSMutableArray *tagArr = [NSMutableArray arrayWithCapacity:houseModel.listTag.count];
    for (int i = 0; i < houseModel.listTag.count; i++) {
        SISSHouseResourceTagModel *model = houseModel.listTag[i];
        
        [tagArr addObject:@{@"tag": model.tag}];
    }
    
    NSDictionary *parameters = @{
                                 @"houseInfoNo":houseModel.houseInfoNo,
                                 @"contractNo":houseModel.contractNo,
                                 @"propertyState":houseModel.propertyState,
                                 @"neighbourhood":houseModel.neighbourhood,
                                 @"region":houseModel.region,
                                 @"regionDetail":houseModel.regionDetail,
                                 @"floor":@(houseModel.floor),
                                 @"totalFloor":@(houseModel.totalFloor),
                                 @"houseType":houseModel.houseType,
                                 @"area":@(houseModel.area),
                                 @"price":@(houseModel.price),
                                 @"averagePrice":@(houseModel.averagePrice),
                                 @"decoration":houseModel.decoration,
                                 @"year":@(houseModel.year),
                                 @"direction":houseModel.direction,
                                 @"otherdesc":houseModel.otherdesc,
                                 @"phoneNumber":houseModel.phoneNumber,
                                 @"name":houseModel.name,
                                 @"spId":@([SISSUserAccount shared].sp_id),
                                 @"listTag":tagArr.copy
                                 };
    

    [kLoginNetworkingManager POSTWithURLString:URL_ENROLL_HOUSE parameters:parameters success:^(id responseObject) {
        
        NSLog(@"3.1.1 房源登记: responseObject-->%@",responseObject);
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } faile:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 3.1.2 客源登记
- (void)enrollPassengerResourceWithHouseModel:(SISSPassengerResourceModel *)passengerModel successBlock:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"spId":@([SISSUserAccount shared].sp_id),
                                 @"region":passengerModel.region,
                                 @"regionDetail":passengerModel.regionDetail,
                                 @"neighbourhood":passengerModel.neighbourhood,
                                 @"houseType":passengerModel.houseType,
                                 @"minPrice":@(passengerModel.minPrice),
                                 @"maxPrice":@(passengerModel.maxPrice),
                                 @"minArea":@(passengerModel.minArea),
                                 @"maxArea":@(passengerModel.maxArea),
                                 @"minFloor":@(passengerModel.minFloor),
                                 @"maxFloor":@(passengerModel.maxFloor),
                                 @"decoration":passengerModel.decoration,
                                 @"direction":passengerModel.direction,
                                 @"purpose":passengerModel.purpose,
                                 @"otherdesc":passengerModel.otherdesc,
                                 @"phoneNumber":passengerModel.phoneNumber,
                                 @"name":passengerModel.name,
                                 @"idNumber":passengerModel.idNumber
                                 };

    [SISSPublicSingleton shared].isHud = NO;//
    NSString *urlString = [URL_ENROLL_PASSENGER stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    [kLoginNetworkingManager POSTWithURLString:urlString parameters:parameters success:^(id responseObject) {
        NSLog(@"3.1.2 客源登记: responseObject-->%@",responseObject);
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } faile:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 3.2.1 筛选已获得委托未发布合作的房源
- (void)requestHouseCooperationWithparameters:(NSDictionary *)parameters success:(void (^)(NSArray<SISSHouseResourceModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
    
     NSString *urlString = [URL_ENROLL_HOUSE_COOPERATION stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    [kLoginNetworkingManager POSTWithURLString:urlString parameters:parameters success:^(id responseObject) {
        NSLog(@"3.2.1 筛选已获得委托未发布合作的房源: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
            return;
        }
        
        NSArray *dataArr = responseObject[@"data"];
        
        NSArray *houseResourceArr = [NSArray yy_modelArrayWithClass:[SISSHouseResourceModel class] json:dataArr];
        if (successBlock) {
            successBlock(houseResourceArr);
        }
        
    } faile:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];

}


// 3.2.2 筛选已获得委托未发布合作的客源
- (void)requestPassengerCooperationWithparameters:(NSDictionary *)parameters success:(void (^)(NSArray<SISSPassengerResourceModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
    
     NSString *urlString = [URL_ENROLL_PASSENGER_COOPERATION stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    [kLoginNetworkingManager POSTWithURLString:urlString parameters:parameters success:^(id responseObject) {
        NSLog(@"3.2.2 筛选已获得委托未发布合作的客源: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
            return;
        }
        
        NSArray *dataArr = responseObject[@"data"];
 
        NSArray *houseResourceArr = [NSArray yy_modelArrayWithClass:[SISSPassengerResourceModel class] json:dataArr];
        if (successBlock) {
            successBlock(houseResourceArr);
        }
        
    } faile:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}


// 6.1.1 修改线下房源
- (void)updateHouseResourceWithHouseModel:(SISSHouseResourceModel *)houseModel successBlock:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"id":@(houseModel.ID),
                                 @"asoId":@(houseModel.asoId),
                                 @"houseInfoNo":houseModel.houseInfoNo,
                                 @"contractNo":houseModel.contractNo,
                                 @"propertyState":houseModel.propertyState,
                                 @"neighbourhood":houseModel.neighbourhood,
                                 @"region":houseModel.region,
                                 @"regionDetail":houseModel.regionDetail,
                                 @"floor":@(houseModel.floor),
                                 @"totalFloor":@(houseModel.totalFloor),
                                 @"houseType":houseModel.houseType,
                                 @"area":@(houseModel.area),
                                 @"price":@(houseModel.price),
                                 @"averagePrice":@(houseModel.averagePrice),
                                 @"decoration":houseModel.decoration ,
                                 @"year":@(houseModel.year),
                                 @"direction":houseModel.direction,
                                 @"otherdesc":houseModel.otherdesc,
                                 @"phoneNumber":houseModel.phoneNumber,
                                 @"name":houseModel.name,
                                 @"spId":@([SISSUserAccount shared].sp_id)
                                 };
    
    NSString *urlString = [URL_UPDATE_HOUSE stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    [kLoginNetworkingManager POSTWithURLString:urlString parameters:parameters success:^(id responseObject) {
        
        NSLog(@"6.1.1 修改线下房源: responseObject-->%@",responseObject);
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } faile:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 6.1.2 更新线下客源
- (void)updatePassengerResourceWithPassengerModel:(SISSPassengerResourceModel *)passengerModel successBlock:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"id":@(passengerModel.ID),
                                 @"neighbourhood":passengerModel.neighbourhood,
                                 @"region":passengerModel.region,
                                 @"regionDetail":passengerModel.regionDetail,
                                 @"minFloor":@(passengerModel.minFloor),
                                 @"maxFloor":@(passengerModel.maxFloor),
                                 @"houseType":passengerModel.houseType,
                                 @"minArea":@(passengerModel.minArea),
                                 @"maxArea":@(passengerModel.maxArea),
                                 @"minPrice":@(passengerModel.minPrice),
                                 @"maxPrice":@(passengerModel.maxPrice),
                                 @"decoration":passengerModel.decoration,
                                 @"direction":passengerModel.direction,
                                 @"otherdesc":passengerModel.otherdesc,
                                 @"purpose":passengerModel.purpose,
                                 @"phoneNumber":passengerModel.phoneNumber,
                                 @"name":passengerModel.name,
                                 @"idNumber":passengerModel.idNumber,
                                 @"spId":@([SISSUserAccount shared].sp_id),
                                 };
    
    [SISSPublicSingleton shared].isHud = NO;//
    NSString *urlString = [URL_UPDATE_PASSENGER stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    [kLoginNetworkingManager POSTWithURLString:urlString parameters:parameters success:^(id responseObject) {
        
        NSLog(@"6.1.2 更新线下客源: responseObject-->%@",responseObject);
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } faile:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

#pragma mark - 2.0

// 3.1.3 插入线下出租信息 (图文上传)
- (void)insertLeaseResourceOfflineWithRentOutModel:(SISSRentOutModel *)rentOutModel imagesArray:(NSArray *)imagesArray successBlock:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"spId":@([SISSUserAccount shared].sp_id),
                                 @"certificateType":@(rentOutModel.certificateType),
                                 @"propertyNumber":rentOutModel.propertyNumber,
                                 @"unitCode":rentOutModel.unitCode,
                                 @"propertyName":rentOutModel.propertyName,
                                 @"idNumber":rentOutModel.idNumber,
                                 @"mobile":rentOutModel.mobile,
                                 @"region":rentOutModel.region,
                                 @"regionDetail":rentOutModel.regionDetail,
                                 @"neighbourhood":rentOutModel.neighbourhood,
                                 @"monthlyRent":rentOutModel.monthlyRent,
                                 @"houseType":rentOutModel.houseType,
                                 @"area":rentOutModel.area,
                                 @"houseConfigure":rentOutModel.houseConfigure,
                                 @"houseFeature":rentOutModel.houseFeature,
                                 @"foregift":rentOutModel.foregift,
                                 @"pay":rentOutModel.pay,
                                 @"floor":rentOutModel.floor,
                                 @"totalFloor":rentOutModel.totalFloor,
                                 @"decoration":rentOutModel.decoration,
                                 @"direction":rentOutModel.direction,
                                 @"otherdesc":rentOutModel.otherdesc
                                 };
    
    [SISSPublicSingleton shared].isHud = NO;//
    NSString *urlString = [URL_INSERT_LEASE_OFFLINE stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    [kLoginNetworkingManager uploadFilesWithURLStr:urlString serverName:@"file" imagesArray:imagesArray parameters:parameters success:^(id responseObject) {
        NSLog(@"3.1.3 插入线下出租信息 (图文上传): responseObject-->%@",responseObject);
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } failed:^(NSError *error) {
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 3.1.4 插入线下租客信息
- (void)insertTenantResourceOfflineWithTenantModel:(SISSTenantModel *)tenantModel successBlock:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"spId":@([SISSUserAccount shared].sp_id),
                                 @"region":tenantModel.region,
                                 @"regionDetail":tenantModel.regionDetail,
                                 @"neighbourhood":tenantModel.neighbourhood,
                                 @"minPrice":tenantModel.minPrice,
                                 @"maxPrice":tenantModel.maxPrice,
                                 @"houseType":tenantModel.houseType,
                                 @"houseConfigure":tenantModel.houseConfigure,
                                 @"houseFeature":tenantModel.houseFeature,
                                 @"residents":tenantModel.residents,
                                 @"checkinTime":tenantModel.checkinTime,
                                 @"houseConfigure":tenantModel.houseConfigure,
                                 @"houseFeature":tenantModel.houseFeature,
                                 @"decoration":tenantModel.decoration,
                                 @"direction":tenantModel.direction,
                                 @"otherdesc":tenantModel.otherdesc,
                                 @"renterName":tenantModel.renterName,
                                 @"idNumber":tenantModel.idNumber,
                                 @"mobile":tenantModel.mobile
                                 };
    
    [SISSPublicSingleton shared].isHud = NO;//
    NSString *urlString = [URL_INSERT_TENANT_OFFLINE stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    [kLoginNetworkingManager POSTWithURLString:urlString parameters:parameters success:^(id responseObject) {
        NSLog(@"3.1.4 插入线下租客信息: responseObject-->%@",responseObject);
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } faile:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

//  6.1.3 修改线下出租
- (void)updateRentOutResourceWithRentOutModel:(SISSRentOutModel *)rentOutModel imagesArray:(NSArray *)imagesArray successBlock:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"id":@(rentOutModel.ID),
                                 @"spId":@([SISSUserAccount shared].sp_id),
                                 @"certificateType":@(rentOutModel.certificateType),
                                 @"propertyNumber":rentOutModel.propertyNumber,
                                 @"unitCode":rentOutModel.unitCode,
                                 @"propertyName":rentOutModel.propertyName,
                                 @"idNumber":rentOutModel.idNumber,
                                 @"mobile":rentOutModel.mobile,
                                 @"region":rentOutModel.region,
                                 @"regionDetail":rentOutModel.regionDetail,
                                 @"neighbourhood":rentOutModel.neighbourhood,
                                 @"monthlyRent":rentOutModel.monthlyRent,
                                 @"houseType":rentOutModel.houseType,
                                 @"area":rentOutModel.area,
                                 @"houseConfigure":rentOutModel.houseConfigure,
                                 @"houseFeature":rentOutModel.houseFeature,
                                 @"foregift":rentOutModel.foregift,
                                 @"pay":rentOutModel.pay,
                                 @"floor":rentOutModel.floor,
                                 @"totalFloor":rentOutModel.totalFloor,
                                 @"decoration":rentOutModel.decoration,
                                 @"direction":rentOutModel.direction,
                                 @"otherdesc":rentOutModel.otherdesc
                                 };
    
    [SISSPublicSingleton shared].isHud = NO;//
    NSString *urlString = [URL_UPDATE_OFFLINE_RENT_OUT stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    [kLoginNetworkingManager uploadFilesWithURLStr:urlString serverName:@"file" imagesArray:imagesArray parameters:parameters success:^(id responseObject) {
        NSLog(@"6.1.3 修改线下出租 (图文上传): responseObject-->%@",responseObject);
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } failed:^(NSError *error) {
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 6.1.4 更新线下租客
- (void)updateTenantResourceWithTenantModel:(SISSTenantModel *)tenantModel successBlock:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"id":@(tenantModel.ID),
                                 @"spId":@([SISSUserAccount shared].sp_id),
                                 @"region":tenantModel.region,
                                 @"regionDetail":tenantModel.regionDetail,
                                 @"neighbourhood":tenantModel.neighbourhood,
                                 @"minPrice":tenantModel.minPrice,
                                 @"maxPrice":tenantModel.maxPrice,
                                 @"houseType":tenantModel.houseType,
                                 @"houseConfigure":tenantModel.houseConfigure,
                                 @"houseFeature":tenantModel.houseFeature,
                                 @"residents":tenantModel.residents,
                                 @"checkinTime":tenantModel.checkinTime,
                                 @"houseConfigure":tenantModel.houseConfigure,
                                 @"houseFeature":tenantModel.houseFeature,
                                 @"decoration":tenantModel.decoration,
                                 @"direction":tenantModel.direction,
                                 @"otherdesc":tenantModel.otherdesc,
                                 @"renterName":tenantModel.renterName,
                                 @"idNumber":tenantModel.idNumber,
                                 @"mobile":tenantModel.mobile
                                 };
    
    [SISSPublicSingleton shared].isHud = NO;//
    NSString *urlString = [URL_UPDATE_OFFLINE_TENANT stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    [kLoginNetworkingManager POSTWithURLString:urlString parameters:parameters success:^(id responseObject) {
        NSLog(@"6.1.4 更新线下租客: responseObject-->%@",responseObject);
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } faile:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

@end
